<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .list {
            width: 990px;
            margin: 0 auto;
            display: flex;
            flex-wrap: wrap;
        }

        .item {
            width: 240px;
            /* margin-left: 10px; */
            padding: 20px 30px;
            transition: all .5s;
            margin-bottom: 20px;
            background-color: rgba(0, 0, 0, 0.04);
        }

        .item:nth-child(4n) {
            margin-left: 0px;
        }

        .item:hover {
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.188);
            transform: translate3d(0, -4px, 0);
            cursor: pointer;
        }

        .item img {
            width: 100%;
            /* height: 100%; */
        }

        .item .name {
            font-size: 18px;
            margin-bottom: 10px;
            color: darkgray;
        }

        .item .price {
            font-size: 22px;
            color: brown;
        }

        .item .price::before {
            content: "$";
            font-size: 14px;
        }

        .filter {
            display: flex;
            width: 990px;
            margin: 0 auto;
            padding: 50px 30px;
        }

        .filter a {
            padding: 10px 20px;
            background-color: rgba(6, 6, 6, 0.259);
            color: rgb(0, 0, 0);
            text-decoration: none;
            margin-right: 20px;
        }

        /* css实现tab栏切换 */
        filter a:active,
        .filter a:focus {
            background-color: rgba(0, 0, 0, 0.59);
            color: rgb(255, 255, 255);
        }
    </style>
</head>

<body>
    <div class="filter">
        <a data-index="1" href="javascript:;">0-100元</a>
        <a data-index="2" href="javascript:;">100-300元</a>
        <a data-index="3" href="javascript:;">300元以上</a>
        <a href="javascript:;">全部</a>
    </div>
    <div class="list">
        <!-- <div class="item">
            <img src="/pink/js_/高级js/画江湖/幻音阁.png" alt="">
            <p class="name">lxbie</p>
            <p class="price">299</p>
        </div> -->
    </div>
    <script>
        const arr = [{ id: 1, uname: '画江湖之不良人-骆小北', src: '/pink/js_/高级js/画江湖/骆小北.png', price: '200' },
        { id: 2, uname: '画江湖之不良人-姬如雪', src: '/pink/js_/高级js/画江湖/姬如雪.png', price: '100' },
        { id: 3, uname: '画江湖之不良人-旱魃', src: '/pink/js_/高级js/画江湖/旱魃.png', price: '400' },
        { id: 4, uname: '画江湖之不良人-黑白无常', src: '/pink/js_/高级js/画江湖/黑白无常.png', price: '900' },
        { id: 5, uname: '画江湖之不良人-阿姐', src: '/pink/js_/高级js/画江湖/阿姐.png', price: '90' },
        { id: 6, uname: '画江湖之不良人-幻音阁', src: '/pink/js_/高级js/画江湖/幻音阁.png', price: '500' }]

         function shop(arrs) {

            let str = ''
            arrs.forEach(item => {
                // console.log(item);
                const { uname, src, price } = item
                str += `
                    <div class="item">
                        <img src=${src} alt="">
                        <p class="name">${uname}</p>
                        <p class="price">${price}</p>
                     </div>
                `
            });
            document.querySelector('.list').innerHTML = str
        }
        shop(arr)
        document.querySelector('.filter').addEventListener('click', e => {
            // console.log(e.target.dataset.index);
            // const {tagName,dataset}=e.target
          
            if (e.target.tagName === 'A') {
                console.log(11);
                 let  newarr = arr
                if (e.target.dataset.index === '1') {
                    newarr= arr.filter(item => item.price > 0 && item.price <= 100)
                } else if (e.target.dataset.index === '2') {
                    newarr=  arr.filter(item => item.price > 100 && item.price <= 300)
                } else if (e.target.dataset.index === '3') {
                    newarr=  arr.filter(item => item.price > 300)
                }
                shop(newarr)
            }
        })

    </script>
</body>

</html>